package com.paireach.bw.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.blankj.utilcode.utils.NetworkUtils;
import com.paireach.bw.R;
import com.paireach.bw.base.BaseFragment;
import com.paireach.bw.event.AppEvent;
import com.paireach.bw.http.WayBillRequest;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by ${cqc} on 2017/8/4.
 * 错误界面
 */

public class ErrorFragment extends BaseFragment {

    private View rootView;
    private TextView tv_error;
    private String orderCode;
    private Toolbar toolbar;

    public static ErrorFragment getInstance(String orderCode) {
        ErrorFragment frag = new ErrorFragment();
        Bundle bundle = new Bundle();
        bundle.putString("orderCode", orderCode);
        frag.setArguments(bundle);
        return frag;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        orderCode = bundle.getString("orderCode");
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.frag_error, container, false);
        return rootView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        findViews();
        initViews();
    }

    private void initViews() {
        toolbar.setTitle("送货在途");
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getActivity().onBackPressed();
            }
        });
        tv_error.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (NetworkUtils.isConnected()) {
                    AppEvent appEvent = new AppEvent();
                    appEvent.setTag("GetOrderCodeDetail");//通知CommonActivity页面请求数据，然后更新fragment
                    EventBus.getDefault().post(appEvent);
                }else{
                    showToast("网络连接不可用，请稍后重试");
                }
            }
        });
    }

    private void findViews() {
        toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
        tv_error = (TextView) rootView.findViewById(R.id.tv_error);
    }
}
